<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\BaseGoodsGh;

/**
 * BaseGoodsGhSearch represents the model behind the search form about `app\models\BaseGoodsGh`.
 */
class BaseGoodsGhSearch extends BaseGoodsGh
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'qgd_id', 'ghs_id', 'status'], 'integer'],
            [['jg'], 'number'],
            [['bzq', 'fhdz', 'bz', 'addtime'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BaseGoodsGh::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'qgd_id' => $this->qgd_id,
            'ghs_id' => $this->ghs_id,
            'jg' => $this->jg,
            'status' => $this->status,
        ]);

        $query->andFilterWhere(['like', 'bzq', $this->bzq])
            ->andFilterWhere(['like', 'fhdz', $this->fhdz])
            ->andFilterWhere(['like', 'bz', $this->bz])
            ->andFilterWhere(['like', 'addtime', $this->addtime]);

        return $dataProvider;
    }
}
